package pkg

import (
	"fmt"
	"os/exec"
	"runtime"
)

// Open 打开系统默认浏览器
func Open(uri string) error {
	var cmd *exec.Cmd
	switch runtime.GOOS {
	case "windows":
		cmd = exec.Command("cmd", "/c", "start", uri)
	case "darwin":
		cmd = exec.Command("open", uri)
	case "linux":
		cmd = exec.Command("xdg-open", uri)
	default:
		return fmt.Errorf("尚未提供 %s 平台的浏览器支持", runtime.GOOS)
	}
	if cmd == nil {
		return fmt.Errorf("尚未提供 %s 平台的浏览器支持", runtime.GOOS)
	}
	return cmd.Start()
}
